import {defineConfig, loadEnv} from 'vite'
import vue from '@vitejs/plugin-vue'
// 引入resolve
import { resolve } from 'path'
import { env } from 'process'

let url;
if(env.NODE_ENV === 'development') {
  url = 'http://192.168.4.224:10088';
  // url = 'http://192.168.71.32:10088';
}else if(env.NODE_ENV === 'test'){
  url = 'http://sassp-service-v2.cras-uat.crc.com.cn';
}else {
  url = 'http://sassp-service-v2.cras.crc.com.cn';
}
console.log(env.NODE_ENV,'env')
// 文档: https://vitejs.dev/config/ 
export default defineConfig({
  plugins: [vue()],
  base: '/',
  publicPath: env.VUE_APP_PUBLIC_PATH,
  server: {
    host: '0.0.0.0',
    port: '5173',
    proxy: {
      '/state-assets-monitor': {
        target: url,
        changeOrigin: true,
        pathRewrite: {
          "^/state-assets-monitor": "/"
        }
      }
    },
    historyApiFallback: {
      index: '/index.html',
  },
  },
  resolve: {
    // 设置路径别名
    alias: {
      '@': resolve(__dirname, './src'),
      '*': resolve('')
    },
  }
})